package com.neu.icloud.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.neu.icloud.entity.Order;

@Mapper
public interface OrderMapper {

	//生成订单
	@Insert("insert into `order`(orderSource,productId,productMount,orderEndDate,orderState,finishMount,caCop,factoryId)"
			+ "values('线下订单',#{productId},#{productMount},#{orderEndDate},#{orderState},0,null,#{factoryId})")
	public int saveOrder(Order order);
	//修改订单(修改订单状态，修改数量，修改)
	
	public int updateOrder(Order order);
	
	//按id查询订单
	@Select("select * from `order` where orderId=#{orderId}")
	public Order findOrderByOrderId(Integer orderId);
	
	//根据产品id查询订单
	@Select("select count(*) from `order` where productId=#{productId}")
	public int findOrdersByProductId(Integer productId);
	
	//查询该厂全部订单
	@Select("select * from `order` where factoryId=#{factoryId}")
	public List<Order> findAllOrderByFactoryId(Integer factoryId);
	
	//删除订单
	@Delete("delete from `order` where orderId=#{orderId}")
	public int deleteOrderByOrderId(Integer orderId);
}
